/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conversor;

import dao.InstituicaoAcademicaDao;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import modelo.InstituicaoAcademica;

/**
 *
 * @author bruno
 */
@FacesConverter("intituicaoAcademicaConversor")
public class InstituicaoAcademicaConversor implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        //return value.isEmpty() ? null : new PaisDao().ler(Integer.parseInt(value.split("-")[0]));
       // System.out.println("CON: " + value );
        return value.isEmpty() ? null : new InstituicaoAcademicaDao().ler(Integer.parseInt(value));
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        //return value == null ? "" : (((Pais) value).getId() + "-" + ((Pais) value).getDesignacao());
        return value == null ? "" : Integer.toString( ((InstituicaoAcademica)value).getId() ) ;
    }
}
